﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyVoteMVC.BackstageManagement.Controllers;
using MyVoteMVC.Domain;

namespace MyVoteMVC.BackstageManagement.Views
{
    public partial class AddActivity : Form, IActivityView
    {
        public event EventHandler OnAddComplete;

        private IActivityController controller;

        private string activityPid;

        public AddActivity(string activityPid):this()
        {
            this.activityPid = activityPid;
        }

        public AddActivity()
        {
            InitializeComponent();
            controller = new ActivityController(this);
        }

        public void AddActivityComplete(string message)
        {
            MessageBox.Show(message);
            Clear();
        }

        public void ModifyActivityComplete(string message)
        {
            throw new NotImplementedException();
        }

        public void GetActivityComplete(Domain.VT_Activities activity)
        {
            throw new NotImplementedException();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            controller.AddActivity(
                activityPid,
                txtTitle.Text,
                txtContent.Text,
                dtStart.Value.Date,
                dtEnd.Value.Date,
                txtImage.Text,
                cbShowUser.Checked ? 1 : 0,
                0,//cbReadAll.Checked ? 1 : 0,
                cbMultiSubmit.Checked ? 1 : 0);
        }

        void Clear()
        {
            txtContent.Text = "";
            txtTitle.Text = "";
            cbMultiSubmit.Checked = false;
            cbReadAll.Checked = false;
            cbShowUser.Checked = false;
            dtEnd.Value = DateTime.Now;
            dtStart.Value = DateTime.Now;
            txtImage.Text = string.Empty;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
           
        }

        private void btnImage_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "JPEG文件(*.jpg)|*.jpg|PNG文件(*.png)|*.png|GIF文件(*.gif)|*.gif";
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string filePath = openFileDialog1.FileName;
                txtImage.Text = filePath;
            }
        }

        private void AddActivity_FormClosing(object sender, FormClosingEventArgs e)
        {
            OnAddComplete(null, null);
        }


        public void OnSubmitError(string message)
        {
            MessageBox.Show(message);
        }
    }
}
